<?php

namespace App\Providers;

use App\Models\lak\Residential;
use App\Observers\ResidentialObserver;
use Illuminate\Support\ServiceProvider;
use App\Utils\Service\LeakyBucketRateLimiter;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     * 设置桶最大容量及流速gao
     */
    public function register()
    {
        $this->app->singleton(LeakyBucketRateLimiter::class, function($app) {
            $bucketSize = 10; // 桶的最大容量
            $leakRate = 0.1; //漏桶的速率

            return new LeakyBucketRateLimiter($bucketSize, $leakRate);
        });
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Residential::observe(ResidentialObserver::class);
    }
}
